﻿Public Class CapNhatPhieuXuatKho_DAO

    'lấy tất cả data trong bảng ChiTietPhieuXuat
    Public Shared Function SelectAll() As DataTable
        Dim strSQL As String = "select * from ChiTietPhieuXuat"
        Dim dt As DataTable
        dt = SQLProvider.ExecQuery(strSQL)
        Return dt
    End Function

    'lấy tất cả data trong bảng phiếu xuất
    Public Shared Function SelectAllPXK() As DataTable
        Dim strSQL As String = "select * from PhieuXuat"
        Dim dt As DataTable
        dt = SQLProvider.ExecQuery(strSQL)
        Return dt
    End Function

    'insert data vào bảng Phiếu Xuất
    Public Shared Sub InsertPX(_pnk As CapNhatPhieuXuatKho_DTO)
        Dim strSQL As String = "Insert into PhieuXuat(SoPhieu,MaCTY,NgayXuat) values('" & _pnk.SoPhieu & "','" & _pnk.MaCongTy & "','" & _pnk.NgayXuat & "' )"
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub

    'insert data vào bảng Phiếu nhập
    Public Shared Sub Insert(_pnk As CapNhatPhieuXuatKho_DTO)
        Dim strSQL As String = "Insert into ChiTietPhieuXuat(SoPhieu,MaSanPham,SoLuong,DonGia,MaKho) values('" & _pnk.SoPhieu & "','" & _pnk.MaSanPham & "'," & _pnk.SoLuong & "," & _pnk.DonGia & ",'" & _pnk.MaKho & "' )"
        ' Dim strSQL As String = "Update ChiTietPhieuNhap set MaSanPham='" & _pnk.MaSanPham & "' ,SoLuong=" & _pnk.SoLuong & ",DonGia=" & _pnk.DonGia & ", where SoPhieu = '" & _pnk.SoPhieu & "'"
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub

    'delete data bảng phiếu nhập
    Public Shared Sub DeletePX(_pnk As CapNhatPhieuXuatKho_DTO)
        Dim strSQL As String = "delete from PhieuXuat where SoPhieu ='" & _pnk.SoPhieu & "'"
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub

    'delete data bảng chi tiết phiếu xuất
    Public Shared Sub Delete(_pnk As CapNhatPhieuXuatKho_DTO)
        Dim strSQL As String = "delete from ChiTietPhieuXuat where SoPhieu ='" & _pnk.SoPhieu & "'"
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub

    'update lại pxk sau khi điều chỉnh
    Public Shared Sub Update(_pnk As CapNhatPhieuXuatKho_DTO)
        Dim strSQL As String = "Update ChiTietPhieuXuat set SoPhieu='" & _pnk.SoPhieu & "', MaSanPham='" & _pnk.MaSanPham & "' ,SoLuong=" & _pnk.SoLuong & ",DonGia=" & _pnk.DonGia & ",MaKho='" & _pnk.MaKho & "' where id = " & _pnk.id
        SQLProvider.ExecNoneQuery(strSQL)
    End Sub

    Public Shared Function SelectBySP(sp As String) As DataTable
        Dim strSQL As String = "select * from ChiTietPhieuXuat where SoPhieu = '" & sp & "'"
        Dim dt As DataTable
        dt = SQLProvider.ExecQuery(strSQL)
        Return dt
    End Function

    Public Shared Function SelectBySP1(sp As String) As DataTable
        Dim strSQL As String = "select MaSanPham,SoLuong,DonGia,MaKho from ChiTietPhieuXuat where SoPhieu = '" & sp & "'"
        Dim dt As DataTable
        dt = SQLProvider.ExecQuery(strSQL)
        Return dt
    End Function
End Class
